<!--
 * @Description: 协议设置
 * @Author: xiao li
 * @Date: 2021-09-14 14:31:31
 * @LastEditTime: 2022-01-21 11:35:28
 * @LastEditors: xiao li
-->

<template>
  <div class="lb-article-edit">
    <top-nav />
    <div class="page-main">
      <el-form
        @submit.native.prevent
        :model="subForm"
        ref="subForm"
        :rules="subFormRules"
        label-width="120px"
      >
        <el-form-item label="订单超时" prop="over_time">
          <el-input
            placeholder="请输入订单超时时间"
            v-model="subForm.over_time"
          >
            <template slot="append">分钟</template>
          </el-input>
          <lb-tool-tips
            >订单未支付超时时间, 超时将自动取消订单, 单位: 分钟</lb-tool-tips
          >
        </el-form-item>
        <el-form-item label="可退款时间" prop="can_refund_time">
          <el-input
            v-model.number="subForm.can_refund_time"
            placeholder="请输入可退款时间"
          >
            <template slot="append">天</template>
          </el-input>
          <lb-tool-tips
            >订单可发起退款的时间，从订单完成之后计算可退款时间</lb-tool-tips
          >
        </el-form-item>
        <el-form-item label="是否开启协议" prop="is_use">
          <el-radio-group v-model="subForm.is_use">
            <el-radio :label="1">{{ $t('action.ON') }}</el-radio>
            <el-radio :label="0">{{ $t('action.OFF') }}</el-radio>
          </el-radio-group>
          <lb-tool-tips>开启协议，预订场地时将展示协议</lb-tool-tips>
        </el-form-item>
        <el-form-item label="场地预约协议" prop="text">
          <lb-ueditor
            v-model="subForm.text"
            :destroy="true"
            ueditorType="2"
          ></lb-ueditor>
        </el-form-item>
        <el-form-item>
          <lb-button type="primary" @click="submitFormInfo">{{
            $t('action.submit')
          }}</lb-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { reg } from '@/utils/reg'
export default {
  data () {
    return {
      id: '',
      subForm: {
        is_use: 0,
        over_time: '',
        can_refund_time: '',
        text: ''
      },
      subFormRules: {
        is_use: { required: true, type: 'number', message: '请选择是否开启', trigger: 'blur' },
        over_time: { required: true, validator: reg.isNum, text: '订单超时时间', trigger: 'blur' },
        can_refund_time: { required: true, validator: reg.isNum, text: '可退款时间', trigger: 'blur' },
        text: { required: true, type: 'string', message: '请输入场地预约协议', trigger: 'blur' }
      }
    }
  },
  created () {
    this.getDetail()
  },
  methods: {
    async getDetail () {
      let { code, data } = await this.$api.banquet.configInfo()
      if (code !== 200) return
      for (let key in this.subForm) {
        this.subForm[key] = data[key]
      }
    },
    submitFormInfo () {
      this.$refs['subForm'].validate(valid => {
        if (valid) {
          let { subForm } = this
          this.$api.banquet.configUpdate(subForm).then(res => {
            if (res.code === 200) {
              this.$message.success(this.$t('tips.successSub'))
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-article-edit {
  width: 100%;
  .el-form {
    width: 100%;
    .el-form-item {
      margin-bottom: 24px;
      .el-select,
      .el-input {
        width: 300px;
      }
    }
  }
}
</style>
